<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
        
        </el-form>
        <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增班次</el-button>
            </el-col>
        </el-row> -->
        <el-table v-loading="loading" :data="basicaudioList" @selection-change="handleSelectionChange">
            <!-- <el-table-column label="班次编号" align="center" prop="owner_id" /> -->
            <el-table-column label="设备编号" align="center" prop="serials">
            </el-table-column>
            <el-table-column label="设备名称" align="center" prop="name" />
            <el-table-column label="操作员" align="center" prop="option" />
            <el-table-column label="物料总码" align="center" prop="code" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="handleUpdate(scope.row)">修改</el-button>

                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改音乐对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="操作员" prop="option">
                    <el-input v-model="form.option" placeholder="请输入班次名称" />
                </el-form-item>
                <el-form-item label="物料码" prop="code">
                    <el-input :disabled="!form.enable" v-model="form.code" placeholder="请输入班次名称" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>


import { getentering, putEntering, delOwner } from "@/api/entering";

export default {
    name: "Basicaudio",
    data() {
        return {
            // 遮罩层

            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 音乐表格数据
            basicaudioList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                audioCode: null,
                audioEra: null,
                audioAuthor: null,
                audioSource: null,
                audioGeneric: null,
                audioSmallClass: null,
                audioSize: null,
                audioCoverImage: null,
                audioFile: null,
                audioState: null,
            },
            // 表单参数
            form: {
                entering_id: null,
                option: null,
                code: null,
                enable: null,
            },
            // 表单校验
            rules: {
                option: [
                    { required: true, message: "操作员不能为空", trigger: "blur" },
                ],
                // code: [
                //     { required: true, message: "物料码不能为空", trigger: "blur" },
                // ],
                finish: [
                    { required: true, message: "结束时间不能为空", trigger: "blur" },
                ],
            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询音乐列表 */
        getList() {
            this.loading = true;
            getentering(this.queryParams).then(response => {

                this.basicaudioList = response.data.data;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                entering_id: null,
                option: null,
                code: null,
                enable: null,
            };
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.audioId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "新增班次";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {

            this.form = row
            this.open = true;
            this.title = "修改班次";

        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    putEntering(this.form).then(response => {

                        this.$message({
                            message: response.data.msg,
                            type: 'success'
                        });
                        this.open = false;
                        this.getList();
                    });

                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            let data = {
                owner_id: row.owner_id
            }
            this.$confirm('是否确认删除名称为"' + row.name + '"的设备？').then(() => {
                delOwner(data).then((res) => {
                    this.$message({
                        message: res.data.msg,
                        type: 'success'
                    });
                    this.getList();
                    console.log(res);
                })
            })

        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('business/basicaudio/export', {
                ...this.queryParams
            }, `basicaudio_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>